const App = getApp();
const navigationBarHeight = (getApp().diygwstatusBarHeight + 44) + 'px'
Page({
    data: {
        msgs1: [],
        url: App.Config.basePath,
        quan:0,
        total:0
    },

    showModal(message) {
        App.WxService.showModal({
            title: '友情提示',
            content: message,
            showCancel: !1,
        });
    },
    onShareAppMessage: function () {
    },
    onLoad(option) {
        if (option) {
            this.setData({
                globalOption: option
            })
        }

        this.getMsgs1();

    },
    onShow() {

    },
    navigateTo(e) {
        App.navigateTo(e.currentTarget.dataset.url, e.currentTarget.dataset);
    },

    getMsgs1() {
        //调用数据
        let param = {
            f: 1,
            loadmsg: `正在加载中`
        };

        App.HttpService.getData(param, "/dtype_List").then(data => {
            this.setData({
                msgs1: data
            });
        });
    },
    //增加商品数量
    add: function(e) {

        var index = e.currentTarget.dataset.index;
        var cindex = e.currentTarget.dataset.cindex;
        var temp=this.data.msgs1;


        temp[index].more[cindex].bqu++;

        this.setData({
            msgs1:temp,
            quan:this.data.quan+1,
            total:parseFloat(this.data.total)+parseFloat(temp[index].more[cindex].price)
        })


    },
    //减少商品数量
    reduce: function(e) {
        var index = e.currentTarget.dataset.index;
        var cindex = e.currentTarget.dataset.cindex;
        var temp=this.data.msgs1;



        if(temp[index].more[cindex].bqu>0)
        {
            temp[index].more[cindex].bqu--;

            this.setData({
                msgs1:temp,
                quan:this.data.quan-1,
                total:parseFloat(this.data.total)-parseFloat(temp[index].more[cindex].price)
            })
        }
    },

    tijiao(e)
    {

        if (this.data.quan==0) {
            this.showModal("请先选择需要的材料")
        } else {
            wx.setStorageSync("m",this.data.msgs1);
            wx.navigateTo({
                url:"/pages/buy/index?quan="+this.data.quan+"&total="+this.data.total
            })
        }


    }

})